﻿@namespace ThingsGateway.Demo
@using BlazorComponent;
@using Microsoft.AspNetCore.Components.Web;
@using System.Reflection;

@using Opc.Ua
@using ThingsGateway.Foundation.OpcUa;
@using Masa.Blazor
@inherits BasePopupComponentBase

<PModal Persistent Title=@Plc?.OpcUaConfig?.ToString() Value="Visible" Width=1200 ValueChanged=@((a=>{if(!a)
        ClosePopupAsync();})) OnSave="()=>{}" SaveText="关闭">

     <SaveContent Context="save">
@{
#if Plugin
         <MMenu OffsetY Context="menu">
             <ActivatorContent>
                 <MButton @attributes="@menu.Attrs" Color="primary" Class="my-1  mx-2 " Disabled="isDownLoading" Loading="isDownLoading">
                     导出
                     <AppChevronDown></AppChevronDown>
                 </MButton>
             </ActivatorContent>
             <ChildContent>
                 <MList>
                     <MListItem Color="primary" OnClick="DownDeviceExport" Disabled="isDownLoading" >  导出到excel </MListItem>
                     <MListItem Color="primary" OnClick="DeviceImport" Disabled="isDownLoading" >导入到系统</MListItem>
                 </MList>

             </ChildContent>
         </MMenu>
#endif
}
     </SaveContent>

 <ChildContent>
         @if (Visible)
        {

            <MRow Class="pa-4"
          Justify="JustifyTypes.SpaceBetween">
        <MCol Cols="12" Md="6">
            <MTreeview @bind-Value=Selected @bind-Active=Actived SelectionType="SelectionType.Leaf"
                       Items=Nodes TItem=OpcUaTagModel
                       Color="warning" Selectable Activatable OpenOnClick
                       LoadChildren=PopulateBranchAsync
                       TKey=ReferenceDescription ItemKey="r=>r.Tag"
                       Style="height:500px;overflow-y:auto;"
                       ItemText="r=>r.Name"
                       ItemChildren="r=>r.Nodes">

            </MTreeview>

        </MCol>
        <MCol Cols="12" Md="6">
            <MCardText Style="height:500px;overflow-y:auto;">
                @if (Actived?.Count == 0 || Actived?.FirstOrDefault()?.NodeId==null)
                {
                    <div key="title"
                         class="text-h6 font-weight-light grey--text pa-4 text-center">
                        选择左侧节点
                    </div>
                }
                else
                {
                    <ScrollXTransition>
                        <MSheet Outlined Class="ma-0 pa-1">
                            <MRow Align="AlignTypes.Center">
                                <MCol>
                                    <MListItem>
                                        <ItemContent>
                                            <MListItemContent>
                                                <MListItemTitle>NodeId </MListItemTitle>
                                            </MListItemContent>
                                        </ItemContent>
                                    </MListItem>
                                </MCol>
                                <MDivider Vertical Center />
                                <MCol>
                                     <MLabel Class=@($"ma-1")> @Actived.FirstOrDefault().NodeId  </MLabel>
                                </MCol>

                            </MRow>
                        </MSheet>
                        @foreach (var item in nodeAttributes)
                        {
                            <MSheet Outlined Class="ma-0 pa-1">
                                <MRow Align="AlignTypes.Center">
                                    <MCol>
                                        <MListItem>
                                            <ItemContent>
                                                <MListItemContent>
                                                    <MListItemTitle>@item.Name </MListItemTitle>
                                                </MListItemContent>
                                            </ItemContent>
                                        </MListItem>
                                    </MCol>
                                    <MDivider Vertical Center />
                                    <MCol>
                                        <MLabel Class=@($"{(StatusCode.IsBad(item.StatusCode)?"red--text":"green--text")} ma-1")> @item.Value  </MLabel>
                                    </MCol>

                                </MRow>
                            </MSheet>
                        }

                    </ScrollXTransition>

                }
            </MCardText>
        </MCol>

        <MDivider Vertical></MDivider>

    </MRow>

            <MOverlay Absolute Value="overlay" Opacity="0.8">
                 <span class="green--text text--darken-2">
                     @("正在获取OpcUa节点...")
                 </span>
                 <MProgressCircular Indeterminate Width=6 Size="30"></MProgressCircular>
             </MOverlay>
        }
 </ChildContent>
</PModal>
